package com.example.choupaiapp.common.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public abstract class BaseSimplePagerAdapter<T> extends PagerAdapter {

    private List<T> views;
    private Context context;


    public BaseSimplePagerAdapter(Context context, List<T> views) {
        this.context = context;
        this.views = views;
    }

    @Override
    public int getCount() {
        return views.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = CreateItemView(context);
        setViewData(view, views.get(position));
        container.addView(view);
        return view;
    }

    protected abstract void setViewData(View view, T t);

    public abstract View CreateItemView(Context context);

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
